package com.dream.utils.web.tag;

import javax.servlet.jsp.JspException;
import javax.servlet.jsp.jstl.core.ConditionalTagSupport;
import javax.servlet.jsp.tagext.Tag;

/**
 * @copyright evan
 * @author evan
 * @Revision
 * @date 2012/09/22
 */
public abstract class AuthorityTagSupport extends
		ConditionalTagSupport {
	
	private static final long serialVersionUID = 1L;

	public int doStartTag() throws JspException {

		Tag parent = getParent();
		
		//the container tag
		if(parent != null && parent instanceof AuthorityChooseTag) {
			
			AuthorityChooseTag tag = (AuthorityChooseTag)parent;
			
			// this tag has not sub tag 
			if (!tag.hasSubTag())
				return SKIP_BODY; // we've been reeled in

			// handle conditional behavior
			if (condition()) {
				//one sub tag is closed
				tag.subTagColsed();
				return EVAL_BODY_INCLUDE;
			} else {
				return SKIP_BODY;
			}
		} else {// the condition tag 
			if (condition()) {
				return EVAL_BODY_INCLUDE;
			} else {
				return SKIP_BODY;
			}

		}
	}
}
